// 封装具体的接口请求
import request from '@/utils/request'// 引入封装的axios
// import store from '@/store'
// 导出接口方法，在页面调用
// 注册接口
export const registerAPI = ({ username, password, repassword }) => {
  return request({
    url: '/api/reg',
    method: 'POSt',
    data: {
      username,
      password,
      repassword
    }
  })
}
// 登录接口
export const loginAPI = ({ username, password }) => {
  return request({
    url: '/api/login',
    method: 'POSt',
    data: {
      username,
      password
    }
  })
}
// 获取用户信息
export const getUserInfoAPI = () => {
  return request({
    url: '/my/userinfo'
  })
}
// 获取侧边栏数据
export const getMenuListAPI = () => {
  return request({
    url: '/my/menus'
  })
}
// 修改用户信息
export const upDateUserInfoAPI = ({ id, user_pic, username, nickname, email }) => {
  return request({
    url: '/my/userInfo',
    method: 'PUT',
    data: {
      id, username, nickname, email, user_pic
    }
  })
}
// 修改用户头像
export const updataUserAvatarAPI = (avatar) => {
  return request({
    url: '/my/update/avatar',
    method: 'PATCH',
    data: {
      avatar
    }
  })
}
/**
    * 更新-用户密码
    * @param {*} param0 { old_pwd: 旧密码, new_pwd: 新密码, re_pwd: 新密码确认 }
    * @returns Promise对象
    */
export const updatePwdAPI = ({ old_pwd, new_pwd, re_pwd }) => {
  return request({
    url: '/my/updatepwd',
    method: 'PATCH',
    data: {
      old_pwd,
      new_pwd,
      re_pwd
    }
  })
}
/**
    * 获取-文章分类
    * @returns Promise对象
    */
export const getArtCateListAPI = () => {
  return request({
    url: '/my/cate/list'
  })
}
/**
    * 增加-文章分类
    * @param {*} param0 { cate_name: 文章分类名字, cate_alias: 文章分类别名 }
    * @returns Promise对象
    */
export const addArtCateAPI = ({ cate_name, cate_alias }) => {
  return request({
    url: '/my/cate/add',
    method: 'POST',
    data: {
      cate_name,
      cate_alias
    }
  })
}
/**
    * 更新-文章分类
    * @param {*} param0 { id: 文章分类id, cate_name: 文章分类名字, cate_alias: 文章分类别名 }
    * @returns Promise对象
    */
export const updateArtCateAPI = ({ id, cate_name, cate_alias }) => {
  return request({
    url: '/my/cate/info',
    method: 'PUT',
    data: {
      id,
      cate_name,
      cate_alias
    }
  })
}
/**
    * 删除-文章分类
    * @param {*} id 要删除的-文章分类id
    * @returns Promise对象
    */
export const delArtCateAPI = (id) => {
  return request({
    url: '/my/cate/del',
    method: 'DELETE',
    params: {
      id
    }
  })
}
//  发布文章

export const uploadArticleAPI = (fd) => {
  return request({
    url: '/my/article/add',
    method: 'POST',
    data: fd
  })
}
/**
    * 获取文章列表
    * @param {*} param0 { pagenum: 当前页码数, pagesize: 当前页条数, cate_id: 文章分类id, state: 文章状态 }
    * @returns Promise对象
    */
export const getArticleListAPI = ({ pagenum, pagesize, cate_id, state }) => {
  return request({
    url: '/my/article/list',
    params: {
      pagenum,
      pagesize,
      cate_id,
      state
    }
  })
}
/**
    * 获取-文章详情
    * @param {*} id 文章id
    * @returns Promise对象
    */
export const getArticleDetailFn = (id) => {
  return request({
    url: '/my/article/info',
    params: {
      id
    }
  })
}
// 删除文章
export const delArtAPI = (id) => {
  return request({
    url: '/my/article/info',
    method: 'delete',
    params: {
      id
    }
  })
}
